<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
<meta charset="UTF-8"/>
<title>运营平台</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="renderer" content="webkit">
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
<link type="text/css" rel="stylesheet" href="<?php echo get_style_cdnurl();?>paimai/yunying/css/common.css?v=20170207" />
<link type="text/css" rel="stylesheet" href="<?php echo get_style_cdnurl();?>paimai/yunying/css/table.css?v=20170117" />
<link type="text/css" rel="stylesheet" href="<?php echo get_style_cdnurl();?>paimai/yunying/css/jquery-ui.css" />
<script src="<?php echo get_style_cdnurl();?>paimai/yunying/js/jquery-1.11.1.js" type="text/javascript"></script>
<script src="<?php echo get_style_cdnurl();?>paimai/yunying/js/jquery-ui.min.js" type="text/javascript"></script>
 <script src="<?php echo get_style_cdnurl();?>paimai/yunying/js/yunIndex.js" type="text/javascript"></script>
<script src="<?php echo get_style_cdnurl();?>paimai/yunying/js/jquery-ym-datePlugin-0.1.js" type="text/javascript"></script>
<script src="<?php echo get_style_cdnurl();?>paimai/yunying/js/global.js" type="text/javascript"></script>
<script src="<?php echo get_style_cdnurl();?>paimai/cheshan/js/common.js" type="text/javascript"></script>
<script type="text/javascript" src="<?php echo get_style_cdnurl();?>paimai/yunying/js/jquery.placeholder.min.js"></script>
<script type="text/javascript">
 $(function(){
     $("input").placeholder();
     if (navigator.userAgent.indexOf("Safari") > -1) {
       $("input").css("lineHeight","normal !important");
     };
});
</script>

<body>
<div class="header">
<div class="headerCo">
<span>你好,<?php echo ($user_info["real_name"]); ?><a href="<?php echo (WEB_URL); ?>Emp/logout">退出</a></span>
<h1><img src="<?php echo get_style_cdnurl();?>paimai/yunying/images/yun_logo.jpg"></h1>
</div>
</div>

<div class="mian">
    <div class="mianL">
    <dl>
        <dd>
            <a id="menu_sy" href="/Index/index" class="shouye">首页</a>
        </dd>
        <?php foreach ($tree_menu as $key => $value): ?>
          <dd>
            <span id="menu_<?php echo ($value['first_char']); ?>" ><img src="<?php echo get_style_cdnurl();?>paimai/yunying/images/yun_jia.jpg"><?php echo ($value['name']); ?></span>
            <ul style="display: none;">
                <?php if (!empty($value['children'])): ?>
                    <?php foreach ($value['children'] as $k => $v): ?>
                        <li><a id='menu_<?php echo ($v["first_char"]); ?>' href="<?php echo ($v['url']); ?>"><?php echo ($v['name']); ?></a></li>
                    <?php endforeach ?>
                <?php endif ?>
            </ul>
        <?php endforeach ?>
    </dl>
</div>

<?php $menu = 'spgl.ccgl'; ?>
<?php $menu=json_encode(explode('.', $menu)); ?>
<script>
    $(function () {
        var cur_menu = '<?php echo ($menu); ?>', cur_menu = eval('[' + cur_menu + ']'), cur_menu = cur_menu[0];
        if (cur_menu == "sy") {
            $("#menu_sy").removeClass('shouye').addClass('current');
        }
        $('#menu_' + cur_menu[0]).click();
        $('#menu_' + cur_menu[0]).find("img").attr("src", "http://img1.isou365.cn/paimai/yunying/images/yun_jie.jpg");
        $(".mianL").css("height", $(document).height() - 95);
        $('#menu_' + cur_menu[1]).addClass('current');
    });
</script>
    <div class="mianR">
        <h3 class="yonghu"><a href="/Car">上拍</a>-><a href="/AuOrder/scene">场次管理</a></h3>
        <input type="hidden" name="branch_id" value="<?php echo ($branch_id); ?>">
        <div class="shangFrom shangFrom1 clearfix">
            <div class="chang-ci">
                <input type="button" value="新建场次" id="xinjian"/>
            </div>
            <div class="deng-ji">
            <select id="location_area" name="location_area" class="branch_company">
                <?php if(count($bc_city) > 1): ?><option value="">请选择所在地</option><?php endif; ?>
                <?php if(is_array($bc_city)): $i = 0; $__LIST__ = $bc_city;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$city): $mod = ($i % 2 );++$i;?><option value="<?php echo ($key); ?>"><?php echo ($city); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
            </select>
            </div>
            <div class="deng-ji"><input type="text" name="keyword" value="场次名称" onfocus="if (this.value == '场次名称') {
                        this.value = ''
                    }" onblur="if (this.value == '') {
                                this.value = '场次名称'
                            }"/></div>
            <div class="shangSou"><input type="button" id="searchBtn"  value="搜索"/></div>
        </div>

        <div class="listBox" id="listBox">
        </div>


        <!--新建场次-->
        <div class="yunBei"></div>
        <div class="tanShang2" style="height:400px;margin-top: -200px">
            <h3>新建场次</h3>
            <ul>
                <li class="clearfix"><span>场次名称</span><input type="text" name="name" value=""/></li>
                <li class="clearfix"><span>开场时间</span><input type="text" name="starttime" class="shijian" value="" id="start_time"/></li>
                <li class="clearfix">
                    <span>所属分公司</span>
                    <select class="branch_company" name="branch_company" id="branch_company">
                        <?php if($branch_id == 0): ?><option value="0">请选择分公司</option>
                            <?php if(is_array($compony_list)): foreach($compony_list as $key=>$company): ?><option value="<?php echo ($key); ?>" <?= $key == $branch_id ? selected : ''; ?> ><?php echo ($company); ?></option><?php endforeach; endif; ?>
                        <?php else: ?>
                            <?php if(is_array($compony_list)): foreach($compony_list as $key=>$company): ?><option value="<?php echo ($key); ?>" <?= $key == $branch_id ? selected : ''; ?> ><?php echo ($company); ?></option><?php endforeach; endif; endif; ?>
                    </select>
                </li>

                <li class="clearfix"><span>所属城市</span>
                    <select id="city" name="city" class="branch_company">
                        <?php if(count($bc_city) > 1): ?><option value="">请选择所属城市</option><?php endif; ?>
                        <?php if($branch_id != 0): if(is_array($bc_city)): foreach($bc_city as $key=>$city): ?><option value="<?php echo ($key); ?>" <?= $key == $city_code ? selected : ''; ?> ><?php echo ($city); ?></option><?php endforeach; endif; endif; ?>
                    </select>
                </li>
                <li class="clearfix"><span>选择活动</span>
                    <select id="scene_activity" name="scene_activity" class="scene_activity branch_company">
                            <option value="0">请选择活动</option>
                            <?php if($branch_id != 0): ?><!--<option value="">请选择活动</option>-->
                                <?php if(is_array($scene_activity_list)): $i = 0; $__LIST__ = $scene_activity_list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$activity): $mod = ($i % 2 );++$i;?><option class="<?php echo ($activity["branch_id"]); ?>" value="<?php echo ($activity["id"]); ?>">
                                        <?php echo ($activity["name"]); ?>
                                    </option><?php endforeach; endif; else: echo "" ;endif; endif; ?>
                    </select>
                </li>

                <div id="showOption" style="display:none">
                    <?php if(is_array($scene_activity_list)): $i = 0; $__LIST__ = $scene_activity_list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$activity): $mod = ($i % 2 );++$i;?><option class="<?php echo ($activity["branch_id"]); ?>" value="<?php echo ($activity["id"]); ?>">
                            <?php echo ($activity["name"]); ?>
                        </option><?php endforeach; endif; else: echo "" ;endif; ?>
                </div>
                <div id="compony_city_list" style="display:none">
                    <option style="color: rgb(0, 0, 0);">选择城市</option>
                    <?php if(is_array($compony_city_list)): $i = 0; $__LIST__ = $compony_city_list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$city): $mod = ($i % 2 );++$i;?><option class="<?php echo ($city["branch_id"]); ?>" value="<?php echo ($city["city_code"]); ?>"><?php echo ($city["name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
                </div>
                <li class="clearfix">
                    <input type="button" value="确定" class="queding" id="scene_submit"/>
                    <input type="button" value="取消" class="quxiao"/>
                    <input type="hidden" name="scene_id" value=""/>
            </ul>
        </div>
        <!--新建场次结束-->

        <div class="clear"></div>
    </div>
</div>
<script type="text/javascript">
    $("#start_time").ymdateplugin({
        showTimePanel: true,
        changeMonth: true,
        changeYear: true,
        onClose: function( selectedDate ) {
            var branch_id = $("#branch_company").val()
            if(branch_id>0){
                getAvailableActivity(branch_id,selectedDate)
            }
        }
    })

    get_list();

    $("#branch_company").change(function(){
        var branch_id = $(this).val();
        if(branch_id>0){
            getDataByBranchId(branch_id);
            var start_time = $('input[name=starttime]').val()
            if(start_time != ''){
                getAvailableActivity(branch_id,start_time);
            }
        }
    });

    // 通过分公司编号，得到活动和场次信息
    function getDataByBranchId(value) {
        //隐藏所有下拉列表的值
        $(".scene_activity option").each(function(){
            if($(this).val()!='0'){
                $(this).remove();
            }
        });

        //根据所属分公司，显示城市列表
        $("#city").empty()
                .append('<option value="0" style="color: rgb(0, 0, 0);">选择城市</option>')
                .append($("#compony_city_list ." + value).clone());
    }



    function getAvailableActivity(branch_id,start_time,activity_id) {
        $(".scene_activity").empty().append('<option value="0" style="color: rgb(0, 0, 0);">请选择活动</option>')
        $.post('/AuOrder/get_scene_activity_by_branch_id',{'start_time':start_time,branch_id:branch_id},function (data) {
            if(data.code==200){
                if(data.data){
                    $.each(data.data,function (index,item) {
                        $(".scene_activity").append('<option value="'+ item.id +'" style="color: rgb(0, 0, 0);">'+ item.name +'</option>')
                    })
                }
            }

            if(activity_id > 1){
                $("#scene_activity").find("option[value="+ activity_id +"]").attr("selected",true);
            }
        },'json')
    }

    function get_list() {
        $.get("/AuOrder/scene_list", function (data) {
            $("#listBox").html(data);
        }, "html");
    }

    //ajax 获取分页内容
    function get_page(p) {
        $.get("/AuOrder/scene_list", {'p': p}, function (data) {
            $("#listBox").html(data);
        }, "html");
    }
    //搜索
    $("#searchBtn").on('click', function () {
        var url = '/AuOrder/scene_list';
        var location_area = $('select[name=location_area]').val();
        if (location_area) {
            url += '/location_area/' + location_area;
        }
        var keyword = $('input[name=keyword]').val();
        if (keyword && keyword != '场次名称') {
            url += '/keyword/' + encodeURIComponent(keyword);
        }
        //console.log(url)
        var param = {};
        $.get(url, param, function (data) {
            $("#listBox").html(data);
        }, "html");
    });

    //(新建/编辑)场次提交
    $("#scene_submit").on('click', function () {
        var scene_id = $('input[name=scene_id]').val();
        var name = $('input[name=name]').val();
        if ($.trim(name) == '') {
            shibai_alert('场次名称不能为空');
            return;
        }
        var starttime = $('input[name=starttime]').val();
        if(!starttime){
            shibai_alert('场次开始时间不能为空');
            return;
        }

        var city = $('select[name=city]').val();

        if(!city){
            shibai_alert('请选择所属城市');
            return;
        }

        var scene_activity = $('select[name=scene_activity]').val(); //活动
        var branch_company = $('select[name=branch_company]').val(); //所属分公司

        var param = {
            'scene_id': scene_id,
            'name': name,
            'starttime': starttime,
            'branch_id': branch_company,
            'city': city,
            'scene_activity':scene_activity,
        };
        $("#scene_submit").attr("disabled","disabled").val("正在提交")
        $.post('/AuOrder/add_scene/', param, function (data) {
            if (data.code == '200') {
                btn_alert(data.msg);
                $(".yunBei").css("display", "none");
                $(".tanShang2").fadeOut();
                get_list();
            } else {
                shibai_alert(data.msg);
            }
            $("#scene_submit").removeAttr("disabled").val("确定")
        }, "json");

    });

    $('#xinjian').on('click', function () {
        $('.tanShang2 > h3').text('新建场次');
        $('input[name=scene_id]').val('');
        $('input[name=name]').val('');
        $('input[name=starttime]').val('');
    });
    //编辑建场次窗口
    function edit_scene(scene_id) {
        $(".yunBei").css("display", "block");
        $('.tanShang2 > h3').text('编辑场次');
        $(".tanShang2").fadeIn();
        //获取原始数据
        $.get('/AuOrder/get_scene/scene_id/' + scene_id, null, function (data) {
            if (data.code == '200') {
                if(data.data.branch_id){
                    getDataByBranchId(data.data.branch_id);
                    getAvailableActivity(data.data.branch_id,data.data.starttime,data.data.scene_activity_id)
                    $('#branch_company').val(data.data.branch_id);

                }else{ //如果没有活动，则显示全部城市，不显示活动。只有选择分公司之后，才能显示对应的活动
                   var branch_id = $('input[name=branch_id]').val();
                   if(branch_id == 0){ //如果是总部，显示全部的城市列表。隐藏活动
                        $('#branch_company').val(0);
                        $("#city").empty()
                                .append($("#compony_city_list").html());
                        $(".scene_activity").empty()
                                .append('<option value="0" style="color: rgb(0, 0, 0);">请选择活动</option>')
                   }
                    $('select[name=scene_activity]').val(0);
                }

                $('input[name=scene_id]').val(data.data.scene_id);
                $('input[name=name]').val(data.data.name);
                $('input[name=starttime]').val(data.data.starttime);
                $('select[name=city]').val(data.data.city);
            } else {
                shibai_alert(data.msg)
            }
        }, 'json')

    }

    //禁用启用场次
    function edit_scene_status(scene_id, status) {
        if (status == '-1') {
            if (!confirm('确定要禁用本场次？')) {
                return;
            }
        }
        var param = {
            'scene_id': scene_id,
            'status': status
        };
        $.post('/AuOrder/add_scene', param, function (data) {
            if (data.code == '200') {
                btn_alert(data.msg);
                get_list();
            } else {
                shibai_alert(data.msg);
            }
        }, 'json')
    }
    //取消按钮事件监听
    $(".quxiao").on('click', function () {
        $(".yunBei").css("display", "none");
        $(".tanShang2").fadeOut();
    });


</script>
<div class="yunBei"></div>
<div class="loading"></div>
</body>
</html>